<?php
require_once('PHPUnit/Framework.php');
require_once('../www/SMReceiver/framework.php');

class SMReceiverModelTest extends PHPUnit_Framework_TestCase{
    private $dao=null;
    private $testConfig = array();
    private $content_array=array();
    private $serialized_content=null;
    private $post_array=array();

    protected function setUp(){
        $this->testConfig = parse_ini_file("config.ini");
        $this->content_array = array("transmitter_base_url" => "transmitter_base_url",
                         "application_key" => "application_key",
                         "messages" => array(
                            array(
                                "message" => "test message 1",
                                "message_file" => "test file",
                                "message_line" => "ln 7",
                                "message_type" => 1
                                ),
                            array(
                                "message" => "test message 2",
                                "message_file" => "test file",
                                "message_line" => "ln 7",
                                "message_type" => 2
                                ),
                            array(
                                "message" => "test message 3",
                                "message_file" => "test file",
                                "message_line" => "ln 7",
                                "message_type" => 3
                                ))
                          );
        
        $this->serialized_content = serialize($this->content_array);
        $this->post_array = array("content" => base64_encode($this->serialized_content));

        $this->dao = new SMReceiverModel($this->post_array, new MySQLConnector($this->testConfig['db_host'],
                $this->testConfig['db_user'], $this->testConfig['db_pw'], $this->testConfig['db_name']));
    }

    public function testSanitize(){
        $result = $this->dao->sanitize();
    }

    public function testExtractVars(){
        $result = $this->dao->extractVars($this->post_array);
        
        $this->assertEquals($result['domain'], "transmitter_base_url", "error: data mangled.");
        $this->assertEquals($result['appkey'], "application_key", "error: data mangled.");
        $this->assertEquals(count($result['messages']), 3, "error: data mangled.");
    }
}

?>